#include "StdAfx.h"
#include "ConfigFile.h"


CConfigFile::CConfigFile(void)
{
	CString path; 
	GetModuleFileName(NULL,path.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
	path.ReleaseBuffer(); 
	int pos = path.ReverseFind('\\'); 
	path = path.Left(pos); 
	path += "\\config.ini";
	m_fileName = path.GetBuffer();
	//////////////////////////////////////////////////////////////////////////
	//char dir[1000];
	//GetCurrentDirectoryA(1000, dir);
	//m_fileName = dir;
	//m_fileName += "\\config.ini";
}

CConfigFile::~CConfigFile(void)
{
}

CConfigFile* CConfigFile::GetInstance()
{
	if(m_pInstance == NULL)
		m_pInstance = new CConfigFile;
	return m_pInstance;
}

CConfigFile* CConfigFile::m_pInstance = NULL;

std::string CConfigFile::GetServerName()
{
	char str[1000];
	GetPrivateProfileStringA("server", "server", "localhost", str, 1000, m_fileName.c_str());
	return std::string(str);
}

std::string CConfigFile::GetPort()
{
	char str[1000];
	GetPrivateProfileStringA("server", "port", "1521", str, 1000, m_fileName.c_str());
	return std::string(str);
}

std::string CConfigFile::GetSID()
{
	char str[1000];
	GetPrivateProfileStringA("server", "sid", "orcl", str, 1000, m_fileName.c_str());
	return std::string(str);
}

std::string CConfigFile::GetLastUser()
{
	char str[1000];
	GetPrivateProfileStringA("user", "name", "admin", str, 1000, m_fileName.c_str());
	return std::string(str);
}

void CConfigFile::SaveServerName( const std::string &server )
{
	WritePrivateProfileStringA("server", "server", server.c_str(), m_fileName.c_str());
}

void CConfigFile::SavePort( const std::string &port )
{
	WritePrivateProfileStringA("server", "port", port.c_str(), m_fileName.c_str());	
}

void CConfigFile::SaveSID( const std::string &sid )
{
	WritePrivateProfileStringA("server", "sid", sid.c_str(), m_fileName.c_str());

}

void CConfigFile::SaveLastUser( const std::string &lastUser )
{
	WritePrivateProfileStringA("user", "name", lastUser.c_str(), m_fileName.c_str());

}

